package com.bdqn.controller;

import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * DemoController
 *
 * @author LILIBO
 * @since 2024-09-19
 */
@Controller
public class DemoController {

    @Resource
    private UserService userService;

    /**
     * 测试
     */
    @GetMapping("/hello/{id}")
    public String hello(Model model, HttpServletRequest request, HttpSession session, @PathVariable("id") Long id) {
        User user = userService.getById(id);
        model.addAttribute("user", user);
        model.addAttribute("test", "model");
        request.setAttribute("test", "request");
        session.setAttribute("test", "session");
        request.setAttribute("sex", "xxx");
        return "demo/hello";
    }

    @GetMapping("/list")
    public String list(Model model) {
        List<User> list = userService.list();
        model.addAttribute("list", list);
        return "demo/user";
    }

    @GetMapping("/layout")
    public String layout(Model model) {
        model.addAttribute("usrName", "郴州网红~帅");
        return "layout/index";
    }

    @GetMapping("/test")
    public String test(Model model) {
        model.addAttribute("usrName", "郴州网红~帅");
        return "frame/test";
    }

}
